﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace FlexySys.Web.Core.Handlers
{
    public class FileHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            if (context.User.Identity.IsAuthenticated)
            {
                string fileName = Path.GetFileNameWithoutExtension(context.Request.FilePath);
                string cacheingfileName = Path.GetFileName(context.Request.FilePath);

                string directory = Path.GetDirectoryName(context.Request.FilePath);
                string size = string.Empty;
                string iconPath = string.Empty;


                context.Response.Cache.SetExpires(DateTime.Now.AddMonths(1));
                context.Response.Cache.SetCacheability(HttpCacheability.Public);
                context.Response.Cache.SetValidUntilExpires(false);
                context.Response.ContentType = "image/jpeg";
                context.Response.AddHeader("content-disposition", "inline; filename=" + cacheingfileName);
                context.Response.End();
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}